package com.gao.baseboot.component;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * @author GaoXi
 * @date 2022/2/20 19:32
 */
@Component
@Slf4j
public class MyBeanPostProcessor implements BeanPostProcessor {

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if(beanName.equals("fooBean2")){
            log.info("此时类已经完成属性值的set,{}",((FooBean2)bean).fooBean);
            log.info("postProcessBeforeInitialization");
        }
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if(beanName.equals("fooBean2")) {
            log.info("postProcessAfterInitialization");
        }
        return bean;
    }
}
